﻿Public Class Books1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Assign text to the heading
        myHeading.InnerHtml = "Books for verification"
    End Sub

    Protected Sub SqlDataSource2_Selected(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource2.Selected
        'If datasource is empty
        If (e.AffectedRows < 1) Then
            no_books_lbl.Visible = True
        Else
            no_books_lbl.Visible = False
        End If
        If (e.AffectedRows < 13) Then
            DataPagerBooks.Visible = False
        Else
            DataPagerBooks.Visible = True
        End If
    End Sub
    Protected Sub ListView1_DataBound(sender As Object, e As EventArgs)
        'Display datapager only if there is more than one page to display
        DataPagerBooks.Visible = (DataPagerBooks.PageSize < DataPagerBooks.TotalRowCount)
    End Sub

    Protected Sub btn_findByName_Click(sender As Object, e As EventArgs) Handles btn_findByName.Click
        searchDatabase("BookName", tb_search.Text)
    End Sub

    Protected Sub btn_findByRegion_Click(sender As Object, e As EventArgs) Handles btn_findByCategory.Click
        searchDatabase("Category", tb_search.Text)
    End Sub

    Private Function searchDatabase(ByVal buttonStr As String, ByVal searchStr As String)
        SqlDataSource2.SelectCommand = "SELECT * FROM Books_Complete WHERE " & buttonStr & " LIKE '%" & searchStr & "%' AND IsVerified = 0 ORDER BY DateAdded DESC"
        SqlDataSource2.DataBind()
        Return True
    End Function

End Class